import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

import java.net.URL;

@SuppressWarnings({"checkstyle:Indentation", "checkstyle:SummaryJavadoc", "checkstyle:MissingJavadocType"})
public class TextGraphProcessorTest {

    @SuppressWarnings("checkstyle:Indentation")
    private TextGraphProcessor processor;

    @SuppressWarnings({"checkstyle:Indentation", "checkstyle:MissingJavadocMethod"})
    @Before
    public void setUp() throws Exception {
        // 使用类路径获取测试文件（确保文件放在 src/test/resources/ 目录下）
        URL resource = getClass().getResource("/Easy_Test.txt");
        assertNotNull("Test file not found", resource);
        processor = new TextGraphProcessor(resource.getPath());
        processor.readTextAndBuildGraph();
    }

    /**
     * Easy_Test.txt 内容示例（假设）：
     * the scientist carefully analyzed the data
     * the team requested more data
     *
     * 图中存在桥接词路径：scientist -> carefully -> analyzed
     */

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithBridgeWords() {
        String input = "the scientist analyzed data";
        String expected = "the scientist carefully analyzed the data";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithoutBridgeWords() {
        String input = "team requested more";
        String expected = "team requested more";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithEmptyInput() {
        String input = "";
        String expected = "";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithSingleWord() {
        String input = "scientist";
        String expected = "scientist";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithNonAlphabeticCharacters() {
        String input = "the scientist! analyzed, the data.";
        String expected = "the scientist carefully analyzed the data";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithOnlyNonAlphabeticCharacters() {
        String input = "!@#$%^&*()";
        String expected = "";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings("checkstyle:Indentation")
    @Test
    public void testGenerateNewTextWithUppercaseInput() {
        String input = "THE SCIENTIST ANALYZED DATA";
        String expected = "the scientist carefully analyzed the data";
        assertEquals(expected, processor.generateNewText(input));
    }

    @SuppressWarnings({"checkstyle:Indentation", "checkstyle:LineLength"})
    @Test
    public void testGenerateNewTextWithLongInput() {
        String input = "the scientist carefully analyzed the data wrote a detailed report and shared the report with the team";
        String expected = "the scientist carefully analyzed the data wrote a detailed report and shared the report with the team";
        assertEquals(expected, processor.generateNewText(input));
    }
}
